from django.db import models

# Create your models here.

class Category(models.Model):
	class Meta:
		db_table = 'categories'
		verbose_name_plural  = 'categories'

	def __unicode__(self):
		return u'%s' % (self.name)
	
	category_id = models.IntegerField()
	name = models.CharField(max_length=255)
	url_name = models.CharField(max_length=255)
	entries_quantity = models.IntegerField(blank=True, null=True)
	links_quantity = models.IntegerField(blank=True, null=True)
	updated_at = models.DateTimeField(auto_now=True)
	created_at = models.DateTimeField(auto_now_add=True)

class Entry(models.Model):
	class Meta:
		db_table = 'entries'
		verbose_name_plural = 'entries'
	
	def __unicode__(self):
		return u'%s' % (self.name)
	
	def get_in_categories(self):
		return self.categories.all().values_list('name', 'url_name')
	
	TYPE_CHOICES = (
		('P', 'Page'),
		('E', 'Entry')
	)
	
	categories = models.ManyToManyField(Category, blank=True)
	name = models.CharField(max_length=255)
	url_name = models.CharField(max_length=255)
	content = models.TextField()
	type = models.CharField(max_length=1, choices=TYPE_CHOICES)
	is_active = models.BooleanField()
	updated_at = models.DateTimeField(auto_now=True)
	created_at = models.DateTimeField(auto_now_add=True)

class Link(models.Model):
	class Meta:
		db_table = 'links'
	
	def __unicode__(self):
		return u'%s' % (self.name)
	
	categories = models.ManyToManyField(Category)
	name = models.CharField(max_length=255)
	url = models.URLField(max_length=255)
	is_active = models.BooleanField()
	updated_at = models.DateTimeField(auto_now=True)
	created_at = models.DateTimeField(auto_now_add=True)

class Comment(models.Model):
	class Meta:
		db_table = 'comments'
	
	def __unicode__(self):
		return u'%s @ %s' % (self.autor, self.entry)
	
	entry = models.ForeignKey(Entry)
	autor = models.CharField(max_length=255)
	email = models.EmailField()
	web = models.URLField(max_length=255, blank=True)
	content = models.TextField()
	created_at = models.DateTimeField(auto_now_add=True)
